package com.vodone.v1pin.common.pm
{
	import com.vodone.v1pin.common.delegate.BrandConvertUtil;
	import com.vodone.v1pin.common.delegate.BrandDelegate;
	
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;

	/**
	* 请求成功时派发 
	*/	
	[Event(name="complete")]
	/**
	* 请求失败时派发
	*/	
	[Event(name="fault")]
	/**
	* 开始请求时派发
	*/	
	[Event(name="startLoad")]
	
	public class BrandPM extends EventDispatcher
	{
		/**
		 * 热销品牌 
		 */		
		public static const RXPP:String = "hotbrand";
		/**
		 * 新增品牌 
		 */		
		public static const XZPP:String = "newbrand";
		
		
		public static const STARTLoad:String = "startLoad";
		public static const FAULT:String = "fault";
		
		public var brandList:Array;
		public function BrandPM(target:IEventDispatcher=null)
		{
			super(target);
		}
		
		public function doSearch( type:String , id:String = null ):void
		{
			BrandDelegate.getBrandList(resultHandler,type,id,faultHandler);
			this.dispatchEvent( new Event( STARTLoad ) ); 
		}
		
		public function resultHandler( obj:Object ):void
		{
			brandList = BrandConvertUtil.getBrandList( obj );
			this.dispatchEvent( new Event( Event.COMPLETE ));
		}
		
		private function faultHandler( obj:Object ):void
		{
			this.dispatchEvent( new Event( "fault" ));
		}
	}
}